package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @Author:Domen
 * @Date:2024/3/29 8:36
 */


@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "用户套餐信息")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    /**
     * 查询所有套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("/套餐查询所有")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId){
        Setmeal setmeal = new Setmeal();
        setmeal.setStatus(StatusConstant.ENABLE);
        setmeal.setCategoryId(categoryId);
        List<Setmeal> list = setmealService.list(setmeal);
        return Result.success(list);
    }


    @GetMapping("/{id}")
    public Result<List<DishItemVO>> getDishList(@PathVariable("id") Long id){
        List<DishItemVO> item = setmealService.getDishItemBySetmealId(id);
        return Result.success(item);
    }
}
